#include "PhoneInfo.h"
_LIT(KCM_MNC1,"00");//移动MNC
_LIT(KCM_MNC2,"02");//移动MNC

_LIT(KCU_MNC1,"01");//联通MNC
_LIT(KCU_MNC2,"06");//联通MNC

_LIT(KCT_MNC1,"03");//电信MNC
_LIT(KCT_MNC2,"05");//电信MNC

_LIT(KTT_MNC,"20");//铁通MNC

//TNetWorkType CPhoneInfo::NetWorkType = ENetWorkUnKnow;
CPhoneInfo::CPhoneInfo() :
	CActive(EPriorityStandard), iNetworkInfoPkg(iNetworkInfo)
{
	CActiveScheduler::Add(this);
}
CPhoneInfo::~CPhoneInfo()
{
	Cancel();
	delete iTelephony;
}
void CPhoneInfo::ConstructL()
{
	iTelephony = CTelephony::NewL();
}
CPhoneInfo* CPhoneInfo::NewL()
{
	CPhoneInfo* pSelf = new (ELeave) CPhoneInfo;
	CleanupStack::PushL(pSelf);
	pSelf->ConstructL();
	CleanupStack::Pop();
	return pSelf;
}
void CPhoneInfo::RunL()
{
	CActiveScheduler::Stop();
}
void CPhoneInfo::DoCancel()
{
	iTelephony->CancelAsync(iCancelRequest);
}
CTelephony::TNetworkInfoV1& CPhoneInfo::GetNetWorkInfo()
{
	Cancel();
	iCancelRequest = CTelephony::EGetCurrentNetworkInfoCancel;
	iTelephony->GetCurrentNetworkInfo(iStatus, iNetworkInfoPkg);
	SetActive();
	CActiveScheduler::Start();

	return iNetworkInfo;
}
TNetWorkType CPhoneInfo::GetNetWorkType()
{
#ifdef _WINSCW
	return ENetWorkUnKnow;
#else
//	if (NetWorkType == ENetWorkUnKnow)
		CPhoneInfo* phoneInfo = CPhoneInfo::NewL();
		CleanupStack::PushL(phoneInfo);
		CTelephony::TNetworkInfoV1& networkInfo = phoneInfo->GetNetWorkInfo();
		TNetWorkType networkType = ENetWorkUnKnow;
		TBuf<10> networkid = networkInfo.iNetworkId;
		if (networkid == KCM_MNC1 || networkid == KCM_MNC2)
		{
			networkType = ENetWorkCM;
		}
		else if (networkid == KCU_MNC1 || networkid == KCU_MNC2)
		{
			networkType = ENetWorkUN;
		}
		else if (networkid == KCT_MNC1 || networkid == KCT_MNC2)
		{
			networkType = ENetWorkCT;
		}
		else if (networkid == KTT_MNC)
		{
			networkType = ENetWorkTT;
		}
		CleanupStack::PopAndDestroy(phoneInfo);
//		NetWorkType = networkType;

	return networkType;
#endif

}
